package com.ncmem.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class JsonTool {

    public static Map<String,String> toMap(String j)
    {
        JsonParser parser = new JsonParser();
        JsonObject jsonObj = parser.parse(j).getAsJsonObject();


        Map<String, String> map = new HashMap<String, String>();
        Set<Entry<String, JsonElement>> entrySet = jsonObj.entrySet();
        for (Iterator<Entry<String, JsonElement>> iter = entrySet.iterator(); iter.hasNext(); ){
            Entry<String, JsonElement> entry = iter.next();
            String key = entry.getKey();
            String value = entry.getValue().toString();
            map.put( key, value);
        }
        return map;

    }
}
